<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="UTF-8">
  <head>
    <%@include file="/WEB-INF/jsp/common/head.jsp" %>
    <link rel="stylesheet" href="${APP_PATH}/css/main.css">
    <link rel="stylesheet" href="${APP_PATH}/ztree/zTreeStyle.css">
	<link rel="stylesheet" href="${APP_PATH}/css/pagination.css">
	<link rel="stylesheet" href="${APP_PATH}/css/hao.css">
	<style>
	.tree li {
        list-style-type: none;
		cursor:pointer;
	}
	table tbody tr:nth-child(odd){background:#F4F4F4;}
	table tbody td:nth-child(even){color:#C00;}
	.main2{
	padding-right: 40px;
	padding-left: 21px;
	margin-top: 50px;
	}
	</style>
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container-fluid">
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li style="padding-top:8px;">
				<div class="btn-group">
				  <button type="button" class="btn btn-default btn-success dropdown-toggle" data-toggle="dropdown">
					<i class="glyphicon glyphicon-user"></i> ${smanager.username} <span class="caret"></span>
				  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#"><i class="glyphicon glyphicon-cog"></i> 个人设置</a></li>
						<li><a href="#"><i class="glyphicon glyphicon-comment"></i> 消息</a></li>
						<li class="divider"></li>
						<li><a href="${APP_PATH}/logout.do" target="_parent"><i class="glyphicon glyphicon-off"></i> 退出系统</a></li>
					  </ul>
			    </div>
			</li>
            <li style="margin-left:10px;padding-top:8px;">
				<button type="button" class="btn btn-default btn-danger">
				  <span class="glyphicon glyphicon-question-sign"></span> 帮助
				</button>
			</li>
          </ul>
          <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search...">
          </form>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
       
        
        <div class="col-sm-9  col-md-9  main2">
			<div class="panel panel-default">
			  <div class="panel-heading">
				<h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 分发数据</h3>
			  </div>
			  <div class="panel-body">
<button type="button" class="btn btn-primary" style="float:left;" onclick="assignPermission()"><i class="glyphicon glyphicon-check"></i> 分发道具</button>
<br>
<br>
<br>
                 <ul id="permissionTree" class="ztree"></ul>
			  </div>
			</div>
        </div>
      </div>
    </div>

    <%@include file="/WEB-INF/jsp/common/script.jsp" %>
    <script src="${APP_PATH}/ztree/jquery.ztree.all-3.5.min.js"></script>
    <script src="${APP_PATH}/script/docs.min.js"></script>
	<script src="${APP_PATH}/jquery/jquery.pagination.js"></script>
	<script src="${APP_PATH}/js/layer/layer.js"></script>
	<script src="${APP_PATH}/js/main.js"></script>
    <script type="text/javascript">
        $(function () {
        	$(".list-group-item").click(function(){
			    if($(this).children("ul").css("display")=="none"){  
				    
				  $(this).children("ul").slideDown(100).children("li");  
		        }else{  
				  
				  $(this).childrens("ul").slideUp(100);  
				}  
			});
			  
		   $(".list-group-item2").click(function(){
			   if($(this).children("ul").css("display")=="none"){  
 					    
 				 $(this).children("ul").slideDown(100).children("li"); 
 			   }else{  
 					  
 			     $(this).children("ul").slideUp("fast");  
 			   } 
		   });
			
			// 使用ztree的异步方式读取数据
		    var setting = {
		        check: {
		            enable: true, // 复选框
		            chkboxType:{ "Y" : "ps", "N" : "ps" }
				},
			    view: {
			        selectedMulti: false,
					addDiyDom: function(treeId, treeNode){
						var icoObj = $("#" + treeNode.tId + "_ico");
						if ( treeNode.icon ) {
							icoObj.removeClass("button ico_docu ico_open").addClass("fa fa-fw " + treeNode.icon).css("background","");
						}
					}
			    },
			    async: {
			        enable: true,
			        url:"${APP_PATH}/permission/loadPermissions4Role.do?roleid=${param.id}",
			        autoParam:["id", "name=n", "level=lv"]
			    },
			    callback: {
			        onClick : function(event, treeId, json) {

			        }
			    }
			};
			$.fn.zTree.init($("#permissionTree"), setting);
        });
        
        function assignPermission() {
        	// 判断是否选中复选框
        	var treeObj = $.fn.zTree.getZTreeObj("permissionTree");
        	var nodes = treeObj.getCheckedNodes(true);
        	//alert(nodes.length);
        	// 分配权限
        	var dataObj = {"roleid":"${param.id}"};
        	$.each(nodes, function(i, node){
        		dataObj["ids["+i+"]"] = node.id;
        	});
        	var loadingIndex = -1;
        	$.ajax({
        		url : "${APP_PATH}/role/doassign.do",
        		type : "POST",
        		data : dataObj,
        		beforeSend : function(){
        			loadingIndex = layer.msg('处理中', {icon: 16});
        			return true;
        		},
        		success : function(r){
        			layer.close(loadingIndex);
        			if ( r.success ) {
						layer.msg("权限数据分配成功", {time:100, icon:6}, function(){
	    					window.location.href = "${APP_PATH}/role/list.htm";
						});
        			}
        		}
        	});
        }
    </script>
  </body>
</html>
